package com.jstyle.jclife.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.Button;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.jstyle.jclife.R;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/6/27.
 */

public class ExerciseModeAdapter extends RecyclerViewBaseAdapter<String> {
    @BindView(R.id.bt_exercise_mode)
    Button btExerciseMode;

    public ExerciseModeAdapter(List<String> mDatas) {
        super(mDatas);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        Context context = holder.itemView.getContext();
        btExerciseMode.setText(mDataList.get(position));
        int id = context.getResources().getIdentifier("mode_" + position, "drawable", context.getPackageName());
        Drawable drawable = context.getResources().getDrawable(id);
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            btExerciseMode.setCompoundDrawables(null, drawable, null, null);
        }
        ViewGroup.LayoutParams lp = btExerciseMode.getLayoutParams();
        if (lp instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
            flexboxLp.setFlexBasisPercent(0.25f);
        }
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_exercise_mode;
    }


}
